<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6_2_3-组件数据注入传递数据</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">
    <my-list :count="5"></my-list>
  </div>
  <script>
    const App = Vue.createApp({});
    const listCom = {
      props: {
        count: Number,
      },
      provide() {
        return {
          listCount: this.count,
        };
      },
      template: `
        <div style="border: red solid 10px;">
            <my-item v-for="i in this.count" :index="i"></my-item>
            </div>
            `,
    };
    const itemCom = {
      props: {
        index: Number,
      },
      template: `
        <div style="border: blue solid 10px;">
            <my-label  :index="this.index">
                </my-label>
            </div>
        `,
    };
    const labelCom = {
      props: {
        index: Number,
      },
      inject: ["listCount"],
      template: `
        <div>{{index}}/{{this.listCount}}</div>
        `,
    };
    App.component("my-list", listCom);
    App.component("my-item", itemCom);
    App.component("my-label", labelCom);
    App.mount("#Application");
  </script>
</body>

</html>